package com.pension.servlet.room;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pension.model.dao.RoomDao;
import com.pension.model.dto.Room;

@WebServlet("/room/update.action")
public class RoomUpdateServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		//1. Room 객체를 만들고 사용자가 입력한 데이터를 저장
		Room room = new Room();
		room.setRoomNumber(Integer.parseInt(req.getParameter("roomnumber")));
		room.setRoomName(req.getParameter("roomname"));
		room.setRoomType(req.getParameter("roomtype"));
		room.setMaxPeople(Integer.parseInt(req.getParameter("maxpeople")));
		room.setAcreageSize(Integer.parseInt(req.getParameter("acreagesize")));
		room.setPriceRoom(Integer.parseInt(req.getParameter("priceroom")));
		
		//2. 데이터베이스에 변경된 내용 적용
		RoomDao dao = new RoomDao();
		dao.updateRoom(room);
		
		//3. 목록 페이지로 이동
		resp.sendRedirect("/pension/room/admin.action" +
				"?roomnumber=" + room.getRoomNumber());

	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		doGet(req, resp);
	}
	
}






